//
//  FamousDoctorsViewController.m
//  FastMedical
//
//  Created by 李通 on 16/7/6.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "FamousDoctorsViewController.h"
#import "applyModel.h"
#import "applyCell.h"
#import "auditController.h"

@interface FamousDoctorsViewController ()<UITableViewDelegate,UITableViewDataSource>




@property(nonatomic,weak)UITableView * applyView;

@property(nonatomic,strong)NSArray<applyModel*> * dataArray;


@end

@implementation FamousDoctorsViewController
// 懒加载方式
- (NSArray *)dataArray {
    if (nil == _dataArray) {
        
        // 1. 获取文件路径
        NSString *path = [[NSBundle mainBundle] pathForResource:@"apply.plist" ofType:nil];
        
        // 2. 读取文件内容到临时数组
        NSArray *tempArray = [NSArray arrayWithContentsOfFile:path];
        
        // 3. 定义一个可变数组
        NSMutableArray *mutable = [NSMutableArray array];
        
        // 4. 字典转模型
        for (NSDictionary *dict in tempArray) {
            
            
            applyModel *model = [applyModel applyModelWithDict:dict];
            
            // 把字典里 key值对应的value 赋值给  model 的 属性
            
            
            // 把model 添加到可变数组中
            [mutable addObject:model];
        }
        
        // 为 _dataArray 赋值
        _dataArray = mutable;
    }
    
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    UITableView * applyView = [[UITableView alloc]initWithFrame:self.view.frame];
    
    _applyView = applyView;
    
    applyView.dataSource =self;
    applyView.delegate = self;
    
    

    
    [self.view addSubview:applyView];
    
    [self.applyView registerClass:[applyCell class] forCellReuseIdentifier:@"appcell"];
    
    
}





//多少列
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}
//每列有多少组
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 80;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    auditController *auditVC = [[auditController alloc]init];
    

    applyModel * model = self.dataArray[indexPath.row];
    
    auditVC.model =model;
    
    [self.navigationController pushViewController:auditVC animated:YES];
}
//cell内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    applyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"appcell" forIndexPath:indexPath];
    
    cell.model = self.dataArray[indexPath.row];
    
    

    return cell;
}

@end
